home *** CD-ROM | disk | FTP | other *** search
/ The Games Machine 76 / XENIATGM66.iso / Indiana Jones / Indiana Jones.exe / RESOURCE / PREVIEW.GOB / cog_actor_snake.cog < prev    next >
Text File  |  1999-11-15  |  4KB  |  175 lines

  1. # Jones 3D Cog Script
  2. #
  3. # actor_Snake.cog
  4. #
  5. # [MDR]
  6. #
  7. # Special stuff for snakes.
  8. #
  9. # Rattlesnakes rear up when between 10-15 meters from player
  10. # and play their rattle sound... eewww... scary...
  11. #
  12. # (C) 1999 LucasArts Entertainment Company LLC. All Rights Reserved
  13. #
  14. # ========================================================================================
  15.  
  16. symbols
  17.  
  18.     message        created
  19.     message        aievent
  20.    
  21. # ************************** SOUNDS ****************************
  22.     sound        snd_rattle=fol_rs_rattle.wav    local
  23.  
  24. # ************************** MISC LOCAL VARS *******************
  25.     thing        t_sender                        local
  26.     int            n_event                            local
  27.  
  28.     int            n_sndRattle                        local
  29.     flex        f_attackRange=1.0                local
  30.  
  31. # ************************ SUBROUTINES *************************
  32.  
  33.     flex        PreventSnakeChase                local
  34.     flex        CheckRattleDist                    local
  35.     flex        StopRattleSound                    local
  36.     flex        StartRattleSound                local
  37.  
  38. end
  39.  
  40. # ========================================================================================
  41. code
  42.  
  43. # .................................................................................    
  44. created:
  45.  
  46.     t_sender = GetSenderRef();
  47.  
  48.     AISetMode(t_sender, 0x2000000);                        # Set MODE_NOCHASING
  49.     AISetSubMode(t_sender, 0x20000);                    # Set SUBMODE_SEMICONTINUOUSMOTION
  50.     AISetSubMode(t_sender, 0x1000000);                    # Set SUBMODE_SPECIALTURNS
  51.     SetThingUserData(t_sender, -1);
  52.  
  53.     if ( IsThingModelName(t_sender, "gen_rs.3do") )
  54.     {
  55.         AISetMode(t_sender, 0x10000);                    # Set MODE_WANTALLEVENTS
  56.     }
  57.  
  58.     return;
  59.  
  60.  
  61. # .................................................................................    
  62. aievent:
  63.  
  64.     t_sender = GetSenderRef();
  65.     n_event  = GetParam(0);
  66.  
  67.     if ( n_event == 0x100 )                                #---- SITHAI_EVENTMODECHANGED
  68.     {
  69.         # Switched to MODE_ATTACKING?
  70.         if ( BITTEST(GetParam(1), 0x02) && !BITTEST(GetParam(2), 0x02) )
  71.         {
  72.             if ( IsThingModelName(t_sender, "gen_rs.3do") )
  73.             {
  74.                 call CheckRattleDist;
  75.             }
  76.             return;
  77.         }
  78.     }
  79.     else if ( n_event == 0x40 )                            #---- SITHAI_EVENTMOVETARGETCHANGED
  80.     {
  81.         if ( BITTEST(GetParam(1), 0x02) )
  82.         {
  83.             if ( VectorDist(GetThingPos(t_sender), GetThingPos(GetLocalPlayerThing())) > f_attackRange )
  84.             {
  85.                 call PreventSnakeChase;
  86.             }
  87.         }
  88.         else
  89.         {
  90.             call StopRattleSound;
  91.         }
  92.     }
  93.     else if ( n_event == 0x4000 )                        #---- SITHAI_EVENTFIRE
  94.     {
  95.         if ( IsThingModelName(t_sender, "gen_rs.3do") )
  96.         {
  97.             if ( Rand() > 0.6 )
  98.             {
  99.                 call StartRattleSound;
  100.             }
  101.             else
  102.             {
  103.                 call StopRattleSound;
  104.             }
  105.         }
  106.     }
  107.  
  108.     return;
  109.  
  110.  
  111. # ===================================================================
  112. #    Subroutines
  113. # ...................................................................
  114. #    Assumes t_sender is initialized
  115. # ===================================================================
  116.  
  117. # .................................................................................    
  118. PreventSnakeChase:
  119.  
  120.     Reset();
  121.  
  122.     StopThing(t_sender);                                # Stop the wee beastie
  123.     AISetMode(t_sender, 0x04);                            # Set MODE_SEARCHING
  124.     AIClearMode(t_sender, 0x80602);                        # Clear MODE_(CHASEGOAL|ACTIVE|ATTACKING|TARGETVISIBLE)
  125.     return;
  126.  
  127.  
  128. # .................................................................................    
  129. CheckRattleDist:
  130.  
  131.     Reset();
  132.  
  133.     if ( VectorDist(GetThingPos(t_sender), GetThingPos(GetLocalPlayerThing())) > f_attackRange )
  134.     {
  135.         StopThing(t_sender);
  136.         AISetMode(t_sender, 0x04);                        # Set MODE_SEARCHING
  137.         AIClearMode(t_sender, 0x602);                    # Clear MODE_(ATTACKING|ACTIVE|TARGETVISIBLE)
  138.  
  139.         call StartRattleSound;
  140.  
  141.         return;
  142.     }
  143.  
  144.     # Allow code to fall through to StopRattleSound here...
  145.  
  146. # .................................................................................    
  147. StopRattleSound:
  148.  
  149.     n_sndRattle = GetThingUserData(t_sender);
  150.     if ( n_sndRattle > -1 )
  151.     {
  152.         StopSound(n_sndRattle, 0.8);                    # Halt rattle sound
  153.     }
  154.  
  155.     return;
  156.  
  157.  
  158. # .................................................................................
  159. StartRattleSound:
  160.  
  161.     if ( GetMoveStatus(t_sender) != 0 )                    # SITHPLAYERMOVE_STILL?
  162.         return;
  163.  
  164.     n_sndRattle = PlaySoundThing(snd_rattle, t_sender, 1.0, 2.0, 15.0, 0x881);
  165.     if ( n_sndRattle > -1 )
  166.     {
  167.         SetThingUserData(t_sender, n_sndRattle);
  168.     }
  169.  
  170.     return;
  171.  
  172.  
  173. end
  174.  
  175.